package com.sxj.corejava.code07_面向对象.bms;

/**
 * @author 石小俊
 * @date 2025年01月08日
 */
public class LoanCreditAccount extends CreditAccount implements Loanable {

    private double loanAmount;  // 贷款金额

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void providerLoan(double money) {
        loanAmount += money;
    }

    @Override
    public boolean payLoan(double money) {
        // 当前账户余额+信用额度 >= 还贷金额
        if (getBalance() + getLimit() >= money) {
            // 还贷之后当前贷款金额减少
            loanAmount -= money;
            // 账户余额减少
            setBalance(getBalance() - money);
            return true;
        }
        // 如果账户余额不足,则还贷失败
        return false;
    }

    @Override
    public double queryLoan() {
        return this.loanAmount;
    }
}
